from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-03 14:02:10.658301
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 03, Sep, 2022
Time: 14:02:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3034
Nobs: 768.000 HQIC: -50.6382
Log likelihood: 9807.79 FPE: 8.26345e-23
AIC: -50.8476 Det(Omega_mle): 7.35523e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299902 0.054559 5.497 0.000
L1.Burgenland 0.106605 0.036315 2.936 0.003
L1.Kärnten -0.106859 0.019293 -5.539 0.000
L1.Niederösterreich 0.205938 0.075965 2.711 0.007
L1.Oberösterreich 0.113844 0.073548 1.548 0.122
L1.Salzburg 0.252891 0.038860 6.508 0.000
L1.Steiermark 0.036253 0.050657 0.716 0.474
L1.Tirol 0.106922 0.041039 2.605 0.009
L1.Vorarlberg -0.060710 0.035284 -1.721 0.085
L1.Wien 0.050022 0.065344 0.766 0.444
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060319 0.113340 0.532 0.595
L1.Burgenland -0.034831 0.075441 -0.462 0.644
L1.Kärnten 0.047310 0.040078 1.180 0.238
L1.Niederösterreich -0.176150 0.157808 -1.116 0.264
L1.Oberösterreich 0.394996 0.152788 2.585 0.010
L1.Salzburg 0.290376 0.080728 3.597 0.000
L1.Steiermark 0.105793 0.105233 1.005 0.315
L1.Tirol 0.314511 0.085252 3.689 0.000
L1.Vorarlberg 0.027020 0.073298 0.369 0.712
L1.Wien -0.022087 0.135744 -0.163 0.871
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191384 0.028032 6.827 0.000
L1.Burgenland 0.089632 0.018659 4.804 0.000
L1.Kärnten -0.008597 0.009913 -0.867 0.386
L1.Niederösterreich 0.260556 0.039030 6.676 0.000
L1.Oberösterreich 0.134415 0.037789 3.557 0.000
L1.Salzburg 0.045838 0.019966 2.296 0.022
L1.Steiermark 0.018100 0.026027 0.695 0.487
L1.Tirol 0.093372 0.021085 4.428 0.000
L1.Vorarlberg 0.058240 0.018129 3.213 0.001
L1.Wien 0.118153 0.033573 3.519 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107722 0.028512 3.778 0.000
L1.Burgenland 0.047644 0.018978 2.511 0.012
L1.Kärnten -0.014886 0.010082 -1.476 0.140
L1.Niederösterreich 0.190890 0.039698 4.809 0.000
L1.Oberösterreich 0.290337 0.038435 7.554 0.000
L1.Salzburg 0.111399 0.020308 5.486 0.000
L1.Steiermark 0.102971 0.026472 3.890 0.000
L1.Tirol 0.110693 0.021446 5.161 0.000
L1.Vorarlberg 0.069777 0.018439 3.784 0.000
L1.Wien -0.017307 0.034148 -0.507 0.612
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130332 0.051763 2.518 0.012
L1.Burgenland -0.051204 0.034454 -1.486 0.137
L1.Kärnten -0.040409 0.018304 -2.208 0.027
L1.Niederösterreich 0.169307 0.072072 2.349 0.019
L1.Oberösterreich 0.140804 0.069779 2.018 0.044
L1.Salzburg 0.288035 0.036869 7.812 0.000
L1.Steiermark 0.032987 0.048061 0.686 0.492
L1.Tirol 0.161981 0.038935 4.160 0.000
L1.Vorarlberg 0.100448 0.033476 3.001 0.003
L1.Wien 0.069596 0.061995 1.123 0.262
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055941 0.041214 1.357 0.175
L1.Burgenland 0.040340 0.027433 1.470 0.141
L1.Kärnten 0.050480 0.014574 3.464 0.001
L1.Niederösterreich 0.220293 0.057384 3.839 0.000
L1.Oberösterreich 0.282727 0.055558 5.089 0.000
L1.Salzburg 0.045411 0.029355 1.547 0.122
L1.Steiermark -0.000606 0.038266 -0.016 0.987
L1.Tirol 0.147986 0.031000 4.774 0.000
L1.Vorarlberg 0.072919 0.026653 2.736 0.006
L1.Wien 0.085295 0.049361 1.728 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179085 0.049352 3.629 0.000
L1.Burgenland -0.005683 0.032850 -0.173 0.863
L1.Kärnten -0.061449 0.017452 -3.521 0.000
L1.Niederösterreich -0.084528 0.068715 -1.230 0.219
L1.Oberösterreich 0.196281 0.066529 2.950 0.003
L1.Salzburg 0.056362 0.035152 1.603 0.109
L1.Steiermark 0.231210 0.045822 5.046 0.000
L1.Tirol 0.494114 0.037122 13.311 0.000
L1.Vorarlberg 0.048027 0.031917 1.505 0.132
L1.Wien -0.051317 0.059108 -0.868 0.385
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166361 0.056672 2.936 0.003
L1.Burgenland -0.010334 0.037722 -0.274 0.784
L1.Kärnten 0.067114 0.020040 3.349 0.001
L1.Niederösterreich 0.206261 0.078906 2.614 0.009
L1.Oberösterreich -0.071048 0.076396 -0.930 0.352
L1.Salzburg 0.211536 0.040365 5.241 0.000
L1.Steiermark 0.115662 0.052618 2.198 0.028
L1.Tirol 0.071987 0.042628 1.689 0.091
L1.Vorarlberg 0.121556 0.036650 3.317 0.001
L1.Wien 0.122504 0.067874 1.805 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357246 0.032765 10.903 0.000
L1.Burgenland 0.005768 0.021809 0.264 0.791
L1.Kärnten -0.023359 0.011586 -2.016 0.044
L1.Niederösterreich 0.214092 0.045621 4.693 0.000
L1.Oberösterreich 0.188191 0.044169 4.261 0.000
L1.Salzburg 0.045888 0.023338 1.966 0.049
L1.Steiermark -0.015491 0.030422 -0.509 0.611
L1.Tirol 0.106652 0.024646 4.327 0.000
L1.Vorarlberg 0.073593 0.021190 3.473 0.001
L1.Wien 0.048770 0.039242 1.243 0.214
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040052 0.148437 0.192512 0.157716 0.124562 0.113153 0.065924 0.222365
Kärnten 0.040052 1.000000 -0.003977 0.132696 0.041552 0.095770 0.430869 -0.052321 0.100496
Niederösterreich 0.148437 -0.003977 1.000000 0.337779 0.151462 0.297970 0.107040 0.183395 0.322995
Oberösterreich 0.192512 0.132696 0.337779 1.000000 0.228579 0.330620 0.172683 0.167936 0.264878
Salzburg 0.157716 0.041552 0.151462 0.228579 1.000000 0.147708 0.122411 0.147407 0.133556
Steiermark 0.124562 0.095770 0.297970 0.330620 0.147708 1.000000 0.151305 0.138604 0.079416
Tirol 0.113153 0.430869 0.107040 0.172683 0.122411 0.151305 1.000000 0.115180 0.153215
Vorarlberg 0.065924 -0.052321 0.183395 0.167936 0.147407 0.138604 0.115180 1.000000 0.006841
Wien 0.222365 0.100496 0.322995 0.264878 0.133556 0.079416 0.153215 0.006841 1.000000